package com.arelikebrothers.lottery.data.core.spyder.pip;

import com.arelikebrothers.lottery.data.core.entity.ElevenP5WinCode;
import com.arelikebrothers.lottery.data.core.repository.ElevenP5WinCodeRepos;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.Map;

/**
 * Created by lennon on 12/08/2017.
 */
@Component
@Scope("prototype")
@Logger
public class SqlDbPipeline implements Pipeline {

    @Autowired
    private ElevenP5WinCodeRepos winCodeRepos;

    @Override
    public void process(ResultItems resultItems, Task task) {

        Map<String, Object> allWincode = resultItems.getAll();
        allWincode.forEach((k, v)->{
            ElevenP5WinCode winCode = (ElevenP5WinCode) v;
            winCodeRepos.save(winCode);
        });


    }
}
